<?php
  
  define('ACC', true);
require('./include/init.php');
session_start(); 
//print_r($_SESSION);
$userid = $_SESSION['user_id'];

echo '<head><meta charset = "utf-8"></head>';  
//$userid = 26;
 echo '<h2>日记账&nbsp&nbsp<a href = "dashboard.php">返回虚拟公司主页</a></h2><br/>';   
 
$company = new companymodel();
$companyinfo = $company->getcompanyinfo($userid);
$companyid = $companyinfo['company_id'];
$accounting = new accountingmodel();
 
echo '<h2>公司名称为:' . $companyinfo['company_name'], '&nbsp|&nbsp';
echo '目前所在财年:第' . $companyinfo['company_y'] . '财年', '&nbsp|&nbsp';
echo '目前所在季度:第' . $companyinfo['company_q'] . '季度', '</h2><br/><br/><br/>';

$actionlog = $company->getactionlog($companyid, 10000); 

echo '<table border = "1">';

echo '<tr><td>财年及季度</td><td>经营事件</td><td><table border = "1"><tr><td width = "200">账户名称</td><td width = "100">借方</td><td width = "100">贷方</td><td width = "100">过账</td></tr></table></td></tr>';  
foreach($actionlog as $k=>$v){
           $action_log_id = $v['action_log_id'];
           $dailybooking = $accounting->getdailybooking($action_log_id );
    
           if(!empty($dailybooking)){
           echo '<tr>';
           echo '<td>第' . $v['action_log_y'] . '财年第' .$v['action_log_q']   . '季度</td>';
           echo '<td>' . $v['action_log_content'] . '</td><td><table border = "1">'; 
            

           
           foreach($dailybooking as $key => $value){
               $inputid = $value['input_id'];
               $accountid = $value['account_id'];
               $accountinfo = $accounting->getaccountinfo($accountid);
               $accountname = $accountinfo['account_name_ch'];
               $amount =  $value['amount'];
               $debit_credit =  $value['debit_credit'];
               $posted = $value['posted'];
               /*
               if($posted == 0){
                    $posted = '<a href = "">过账</a>'; 
               }else{                                                                   
                    $posted = '过账';
               }
               */
               
           echo '<tr>';
                if ($debit_credit == 'debit'){
                    echo '<td width = "200">' . $accountname . '</td><td width = "100">' . $amount . '</td><td width = "100"></td><td width = "100">';
                    switch($posted){
                         case 0:
                         echo '<a href = "post.php?inputid=' . $inputid . '&type=post">过账</a></td>';
                         break;
                         case 1:
                         echo '<a href = "post.php?inputid=' . $inputid . '&type=revpost">反过账</a></td>';
                         break;
                         case 2:
                         echo '</td>';
                         break; 
                    }       
                
                }else{
                    echo '<td width = "200">&nbsp&nbsp&nbsp' . $accountname . '</td><td width = "100"></td><td width = "100">' . $amount . '</td><td width = "100">';                                                                                                
                    switch($posted){
                         case 0:
                         echo '<a href = "post.php?inputid=' . $inputid . '&type=post">过账</a></td>';
                         break;
                         case 1:
                         echo '<a href = "post.php?inputid=' . $inputid . '&type=revpost">反过账</a></td>';
                         break;
                         case 2:
                         echo '</td>';
                         break; 
                    } 
                }  
           echo '</tr>'; 
           
           }
           
           }  
     
     echo '</table></td></tr>';
}  
echo '</table><a href="carryover.php">结转损益类账户</a>&nbsp&nbsp</table><a href="accruedincometax.php">计提应付税</a>';
  
?>
